package com.ruoyi.web.controller.basic;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.basic.domain.JcItems;
import com.ruoyi.basic.service.IJcItemsService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 物料信息Controller
 * 
 * @author HK
 * @date 2021-07-18
 */
@Controller
@RequestMapping("/basic/items")
public class JcItemsController extends BaseController
{
    private String prefix = "basic/items";

    @Autowired
    private IJcItemsService jcItemsService;

    @RequiresPermissions("basic:items:view")
    @GetMapping()
    public String items()
    {
        return prefix + "/items";
    }

    /**
     * 查询物料信息列表
     */
    @RequiresPermissions("basic:items:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(JcItems jcItems)
    {
        startPage();
        List<JcItems> list = jcItemsService.selectJcItemsList(jcItems);
        return getDataTable(list);
    }

    /**
     * 导出物料信息列表
     */
    @RequiresPermissions("basic:items:export")
    @Log(title = "物料信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(JcItems jcItems)
    {
        List<JcItems> list = jcItemsService.selectJcItemsList(jcItems);
        ExcelUtil<JcItems> util = new ExcelUtil<JcItems>(JcItems.class);
        return util.exportExcel(list, "物料信息数据");
    }

    /**
     * 新增物料信息
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存物料信息
     */
    @RequiresPermissions("basic:items:add")
    @Log(title = "物料信息", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(JcItems jcItems)
    {
        return toAjax(jcItemsService.insertJcItems(jcItems));
    }

    /**
     * 修改物料信息
     */
    @GetMapping("/edit/{itemId}")
    public String edit(@PathVariable("itemId") Long itemId, ModelMap mmap)
    {
        JcItems jcItems = jcItemsService.selectJcItemsById(itemId);
        mmap.put("jcItems", jcItems);
        return prefix + "/edit";
    }

    /**
     * 修改保存物料信息
     */
    @RequiresPermissions("basic:items:edit")
    @Log(title = "物料信息", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(JcItems jcItems)
    {
        return toAjax(jcItemsService.updateJcItems(jcItems));
    }

    /**
     * 删除物料信息
     */
    @RequiresPermissions("basic:items:remove")
    @Log(title = "物料信息", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(jcItemsService.deleteJcItemsByIds(ids));
    }
}
